--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_remilia_scarlet = General:new(extension, "hy_remilia_scarlet", "chi_k", 3, 3, General.Female)
    local fate_decide = fk.CreateSkill {
        name = "fate_decide",
    }
    fate_decide:addEffect(fk.EventPhaseStart, {
        anim_type = "support",
        can_trigger = function(self, event, target, player)
            return player:hasSkill(fate_decide.name) and target.phase == Player.Judge and player:usedSkillTimes(fate_decide.name, Player.HistoryRound) == 0
        end,
        on_cost = function(self, event, target, player)
            return player.room:askToSkillInvoke(player, {
                skill_name = fate_decide.name,
                prompt = "fate_decide_prompt::" .. player.room.current.id
            })
        end,
        on_use = function(self, event, target, player)
            local room = player.room
            local result = room:askToGuanxing(player, {
                cards = room:getNCards(5),
                top_limit = { 4, 4 },
                bottom_limit = { 1, 1 },
                title = fate_decide.name,
                skill_name = fate_decide.name,
                skip = true,
                area_names = { "Top", "fate_decide_discard" }
            })
            if #result.top > 0 then
                room:moveCardTo(table.reverse(result.top), Card.DrawPile)
            end
            if #result.bottom > 0 then
                room:setPlayerMark(target, "fate_decide_result-turn", Fk:getCardById(result.bottom[1]).color)
                if Fk:getCardById(result.bottom[1]).color == Card.Black then
                    room:setPlayerMark(target, "@fate_decide_result-turn", "fate_decide_black")
                else
                    room:setPlayerMark(target, "@fate_decide_result-turn", "fate_decide_red")
                end
                room:moveCards({
                    ids = result.bottom,
                    toArea = Card.DiscardPile,
                    moveReason = fk.ReasonDiscard,
                    proposer = player,
                    skillName = fate_decide.name,
                })
            end
        end,
    })
    fate_decide:addEffect(fk.DamageCaused, {
        can_refresh = function(self, event, target, player, data)
            return player:getMark("fate_decide_result-turn") == Card.Red and data.from == player
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            data.damage = data.damage + 1
            room:setPlayerMark(player, "fate_decide_result-turn", 0)
            room:setPlayerMark(player, "@fate_decide_result-turn", 0)
        end,
    })
    fate_decide:addEffect(fk.TurnEnd, {
        can_refresh = function(self, event, target, player, data)
            return player:getMark("fate_decide_result-turn") == Card.Black
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            if not player.dead then
                room:drawCards(player, 2, fate_decide.name)
            end
        end,
    })
    local hexagram = fk.CreateSkill {
        name = "hexagram",
        tags = {
            Skill.Switch
        },
    }
    hexagram:addEffect(fk.CardUsing, {
        anim_type = "drawcard",
        can_trigger = function(self, event, target, player, data)
            if not (player:hasSkill(hexagram.name) and player == target) then
                return false
            end
            local state = player:getSwitchSkillState(hexagram.name, false)
            return state == fk.SwitchYang and data.card.color == Card.Black
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if not player.dead then
                room:drawCards(player, 1)
            end
        end
    })
    hexagram:addEffect(fk.CardUseFinished, {
        anim_type = "offensive",
        can_trigger = function(self, event, target, player, data)
            if not (player:hasSkill(hexagram.name) and player == target) then
                return false
            end
            local state = player:getSwitchSkillState(hexagram.name, false)
            return state == fk.SwitchYin and data.card.color == Card.Red
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if #table.filter(player.player_cards[Player.Hand], function(id)
                    return not player:prohibitDiscard(Fk:getCardById(id))
                end) > 0 then
                local cardIds = room:askToDiscard(player, {
                    min_num = 1,
                    max_num = 1,
                    skill_name = hexagram.name,
                    cancelable = false,
                    prompt = "hexagram_prompt",
                    skip = true,
                })
                local card = Fk:getCardById(cardIds[1])
                room:setPlayerMark(player, "hexagram_disable", card.id)
                local target_count = 0
                for _, t in ipairs(room.alive_players) do
                    if player.phase == Player.Play and card.trueName == "slash" then
                        if player:canUseTo(card, t, { bypass_distances = true }) then
                            target_count = target_count + 1
                        end
                    else
                        if player:canUseTo(card, t, { bypass_distances = true, bypass_times = true }) then
                            target_count = target_count + 1
                        end
                    end
                end
                if target_count == 0 then
                    room:throwCard(cardIds, hexagram.name, player, player)
                elseif player.id > 0 or player.serverplayer:getId() > 0 then
                    room:notifyMoveFocus(player, "hexagram_viewas")
                    local success, dat = room:askToUseActiveSkill(player, {
                        skill_name = "hexagram_viewas",
                        prompt = "hexagram_use_prompt:::" .. card:toLogString(),
                    })
                    if success then
                        room:useCard({
                            from = player,
                            tos = dat and dat.targets or {},
                            card = card,
                        })
                    else
                        room:throwCard(cardIds, hexagram.name, player, player)
                    end
                end
                room:setPlayerMark(player, "hexagram_disable", 0)
            end
        end
    })
    hexagram:addEffect("targetmod", {
        mute = true,
        bypass_distances = function(self, player, skill, card, to)
            if player:hasSkill(hexagram.name) and card then
                if type(card) == "number" then
                    return player:getMark("hexagram_disable") == card
                else
                    return player:getMark("hexagram_disable") == card.id
                end
            end
        end,
    })
    local hexagram_viewas = fk.CreateSkill {
        name = "hexagram_viewas",
    }
    hexagram_viewas:addEffect("viewas", {
        mute = true,
        card_num = 1,
        card_filter = function(self, player, to_select, selected)
            if #selected == 0 then
                return to_select == player:getMark("hexagram_disable") and player:canUse(Fk:getCardById(to_select))
            end
        end,
        view_as = function(self, player, cards)
            return Fk:getCardById(player:getMark("hexagram_disable"))
        end,
    })
    local vampire = fk.CreateSkill {
        name = "vampire",
        tags = {
            Skill.Lord
        }
    }
    vampire:addEffect(fk.HpRecover, {
        anim_type = "support",
        can_trigger = function(self, event, target, player, data)
            if not (player:hasSkill(vampire.name) and target ~= player and player:usedSkillTimes(vampire.name, Player.HistoryRound) == 0 and target.kingdom == "chi_k") then
                return false
            end
            return true
        end,
        on_cost = function(self, event, target, player)
            return target.room:askToSkillInvoke(target, {
                skill_name = vampire.name,
                prompt = "vampire_prompt::" .. player.id
            })
        end,
        on_use = function(self, event, target, player)
            if not player.dead then
                player.room:drawCards(player, 2, vampire.name)
            end
        end,
    })
    vampire:addEffect(fk.Damaged, {
        can_trigger = function(self, event, target, player, data)
            if not (player:hasSkill(vampire.name) and target ~= player and player:usedSkillTimes(vampire.name, Player.HistoryRound) == 0 and target.kingdom == "chi_k") then
                return false
            end
            return data.from and data.from == player
        end,
        on_cost = function(self, event, target, player)
            return target.room:askToSkillInvoke(target, {
                skill_name = vampire.name,
                prompt = "vampire_prompt::" .. player.id
            })
        end,
        on_use = function(self, event, target, player)
            if not player.dead then
                player.room:drawCards(player, 2, vampire.name)
            end
        end,
    })
    extension:loadSkillSkels { fate_decide, hexagram, hexagram_viewas, vampire }
    hy_remilia_scarlet:addSkills { "fate_decide", "hexagram", "vampire" }
    Fk:loadTranslationTable {
        ["hy_remilia_scarlet"] = "蕾米莉亚",
        ["#hy_remilia_scarlet"] = "独断之夜王",
        ["designer:hy_remilia_scarlet"] = "黑曜人形",
        ["illustrator:hy_remilia_scarlet"] = "ぎヴちょこ",
        ["cv:hy_remilia_scarlet"] = "",

        ["fate_decide"] = "定命",
        [":fate_decide"] = "每轮限一次，一名角色判定阶段开始时，你可以观看牌堆顶五张牌，交换这些牌的顺序并弃置其中一张牌，若弃置牌为：<br>红色，该角色本回合下次造成伤害+1；<br>黑色，其于本回合结束时摸两张牌。",
        ["fate_decide_prompt"] = "定命：观看牌堆顶五张牌，弃置其中一张并令%dest获得对应增益",
        ["fate_decide_discard"] = "弃置",
        ["@fate_decide_result-turn"] = "定命",
        ["fate_decide_black"] = "黑",
        ["fate_decide_red"] = "红",

        ["hexagram"] = "魔纹",
        [":hexagram"] = "转换技，阳：你使用黑色牌时，摸一张牌。阴：你使用红色牌结算结束后，弃一张手牌，若此牌可以使用则改为使用之（无距离限制且计入出牌阶段限制）。",
        ["hexagram_prompt"] = "魔纹：弃置一张手牌，如果可以使用则改为使用",
        ["hexagram_use_prompt"] = "魔纹：使用%arg",

        ["hexagram_viewas"] = "魔纹",

        ["vampire"] = "红魔",
        [":vampire"] = "主公技，每轮限一次，其他地势力角色回复体力或受到你造成的伤害后，其可以令你摸两张牌。",
        ["vampire_prompt"] = "红魔：令%dest摸两张牌"
    }
end
